package com.laker.autotest;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.EnableSpringUtil;
import com.laker.autotest.utils.PlaywrightUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableSpringUtil
public class AutoTestApplication {

    public static void main(String[] args) {
        // java -jar easy-auto test.jar install 则会安装playwright内置浏览器
        if (args.length > 0 && argsContainInstall(args)) {
            // 安装内置浏览器
            PlaywrightUtil.command(args);
        } else {
            // 检测安装内置浏览器
            PlaywrightUtil.installBrowser("chromium");
            // 启动 Spring Boot 应用程序
            SpringApplication.run(AutoTestApplication.class, args);
        }
        System.out.println("Gitee: https://gitee.com/lakernote/easy-auto-test");
        System.out.println("Start success! ");
    }

    private static boolean argsContainInstall(String[] args) {
        for (String arg : args) {
            if (StrUtil.contains(arg, "install")) {
                return true;
            }
        }
        return false;
    }

}
